package pers.qianyu.util;

import pers.qianyu.util.model.*;

/**
 * @author mizzle rain
 * @date 2021-01-17 17:03
 */
public class ListNodeUtil {
    public static ListNode generateList(int... params) {
        ListNode root = new ListNode(), p = root;
        for (int param : params) {
            p.next = new ListNode(param);
            p = p.next;
        }
        return root.next;
    }

    public static String listToString(ListNode root) {
        ListNode p = root;
        StringBuilder builder = new StringBuilder();
        builder.append("[");
        while (p != null) {
            builder.append(p.val + ",");
            p = p.next;
        }
        builder.replace(builder.length() - 1, builder.length(), "]");
        return builder.toString();
    }
}
